$(function () {
    console.log("登录页面")
    // 给loginForm绑定提交事件
    $('#loginForm').submit(() => {
        // console.log(111)
        // 获取同意协议的按钮
        let agreeValue = $("#agree").prop("checked")
        // console.log(agreeValue)
        if (!agreeValue) {
            // 没有勾选协议
            alert("您未同意协议，无法登录")
            return false;
        }
        // 同意协议 允许登录
        let username = $("#username").val();
        let password = $("#password").val();
        password = md5(password)
        $("#password").val(password)
        console.log(password)
        let jsonLogin = JSON.stringify({username, password});
        // console.log(jsonLogin)
        $.ajax({
            url: '/api/user/login',
            type: "post",
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            data: jsonLogin,
            success:function (result){
                console.log(result)
                let layer = layui.layer
                // alert(result["msg"])
                if(result["code"] == 1008){
                //     // 登录成功
                //     // 跳转到系统首页
                //     window.location.href = "/index.html"
                    layer.alert(result['msg'],function (){
                        // console.log(index)
                        layer.close();
                        window.location.href = "/index.html"
                    })
                }else{
                    layer.alert(result['msg'],function (){
                        // console.log(index)
                        layer.close();
                        window.location.href = "/login.html"
                    })
                }

            }
        })
        return false;
    })
})